package com.dj.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class CustomerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private EurekaClient eurekaClient;

    @GetMapping("/customer")
    public String customer(){
        // 通过eurekaClient获得SEARCH服务的信息
        InstanceInfo search = eurekaClient.getNextServerFromEureka("SEARCH", false);
        // 获取到访问的地址
        String url = search.getHomePageUrl();
        System.out.println(url);
        //通过restTemplate访问
        String res = restTemplate.getForObject(url + "/find", String.class);
        //返回
        return res;
    }
}
